package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Bicicles;
import java.sql.Date; 
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class BiciclesPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Bicicles> list;

public BiciclesPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Bicicles bicicles ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into bicicles(IDBICICLETA,PLACA,MARCA,MODELO,CHASIS,COLOR,ID,TIPOID,ACTIVO,IDMUNICIPIO,FECHA,USERNAME)  values(?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setLong(1,bicicles.getIDBICICLETA());
        pinsert.setString(2,bicicles.getPLACA());
        pinsert.setString(3,bicicles.getMARCA());
        pinsert.setString(4,bicicles.getMODELO());
        pinsert.setString(5,bicicles.getCHASIS());
        pinsert.setString(6,bicicles.getCOLOR());
        pinsert.setString(7,bicicles.getID());
        pinsert.setString(8,bicicles.getTIPOID());
        pinsert.setString(9,bicicles.getACTIVO());
        pinsert.setString(10,bicicles.getIDMUNICIPIO());
        pinsert.setDate(11,bicicles.getFECHA());
        pinsert.setString(12,bicicles.getUSERNAME());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Bicicles bicicles ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update bicicles set  IDBICICLETA=?, PLACA=?, MARCA=?, MODELO=?, CHASIS=?, COLOR=?, ID=?, TIPOID=?, ACTIVO=?, IDMUNICIPIO=?, FECHA=?, USERNAME=?  where  IDBICICLETA ='"+bicicles.getIDBICICLETA()+"' and  IDMUNICIPIO ='"+bicicles.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,bicicles.getIDBICICLETA());
pupdate.setString(2,bicicles.getPLACA());
pupdate.setString(3,bicicles.getMARCA());
pupdate.setString(4,bicicles.getMODELO());
pupdate.setString(5,bicicles.getCHASIS());
pupdate.setString(6,bicicles.getCOLOR());
pupdate.setString(7,bicicles.getID());
pupdate.setString(8,bicicles.getTIPOID());
pupdate.setString(9,bicicles.getACTIVO());
pupdate.setString(10,bicicles.getIDMUNICIPIO());
pupdate.setDate(11,bicicles.getFECHA());
pupdate.setString(12,bicicles.getUSERNAME());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  bicicles set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Bicicles bicicles_old , Bicicles bicicles) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update bicicles set  IDBICICLETA=? ,  IDMUNICIPIO=?  where  IDBICICLETA ='"+bicicles_old.getIDBICICLETA()+"' and  IDMUNICIPIO ='"+bicicles_old.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,bicicles.getIDBICICLETA());pupdate.setString(10,bicicles.getIDMUNICIPIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Bicicles bicicles ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from bicicles  where  IDBICICLETA = ? and  IDMUNICIPIO = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setLong(1,bicicles.getIDBICICLETA());
pdelete.setString(10,bicicles.getIDMUNICIPIO());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from bicicles where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from bicicles  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Bicicles bicicles) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from bicicles where IDBICICLETA='"+bicicles.getIDBICICLETA()+"' and IDMUNICIPIO='"+bicicles.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Bicicles findByPrimaryKey(Bicicles bicicles) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from bicicles where IDBICICLETA='"+bicicles.getIDBICICLETA()+"' and IDMUNICIPIO='"+bicicles.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            bicicles.setIDBICICLETA(rs.getLong("IDBICICLETA"));
bicicles.setPLACA(rs.getString("PLACA"));
bicicles.setMARCA(rs.getString("MARCA"));
bicicles.setMODELO(rs.getString("MODELO"));
bicicles.setCHASIS(rs.getString("CHASIS"));
bicicles.setCOLOR(rs.getString("COLOR"));
bicicles.setID(rs.getString("ID"));
bicicles.setTIPOID(rs.getString("TIPOID"));
bicicles.setACTIVO(rs.getString("ACTIVO"));
bicicles.setIDMUNICIPIO(rs.getString("IDMUNICIPIO"));
bicicles.setFECHA(rs.getDate("FECHA"));
bicicles.setUSERNAME(rs.getString("USERNAME"));
    }
    rs.close();
    psquery.close();
 return bicicles;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDBICICLETA()
*/

public static List<Bicicles> findByIDBICICLETA(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where IDBICICLETA='"+bicicles.getIDBICICLETA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPLACA()
*/

public static List<Bicicles> findByPLACA(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where PLACA='"+bicicles.getPLACA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMARCA()
*/

public static List<Bicicles> findByMARCA(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where MARCA='"+bicicles.getMARCA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMODELO()
*/

public static List<Bicicles> findByMODELO(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where MODELO='"+bicicles.getMODELO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByCHASIS()
*/

public static List<Bicicles> findByCHASIS(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where CHASIS='"+bicicles.getCHASIS()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByCOLOR()
*/

public static List<Bicicles> findByCOLOR(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where COLOR='"+bicicles.getCOLOR()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByID()
*/

public static List<Bicicles> findByID(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where ID='"+bicicles.getID()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTIPOID()
*/

public static List<Bicicles> findByTIPOID(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where TIPOID='"+bicicles.getTIPOID()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByACTIVO()
*/

public static List<Bicicles> findByACTIVO(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where ACTIVO='"+bicicles.getACTIVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDMUNICIPIO()
*/

public static List<Bicicles> findByIDMUNICIPIO(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where IDMUNICIPIO='"+bicicles.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHA()
*/

public static List<Bicicles> findByFECHA(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where FECHA='"+bicicles.getFECHA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUSERNAME()
*/

public static List<Bicicles> findByUSERNAME(Bicicles bicicles,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
      String sql = "select * from bicicles where USERNAME='"+bicicles.getUSERNAME()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Bicicles> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Bicicles>();
  String sql = "select * from bicicles";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from bicicles";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from bicicles where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from bicicles";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from bicicles where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Bicicles> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Bicicles>();
  String sql = "select * from bicicles where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Bicicles> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Bicicles>();
  String sql = "select * from bicicles";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "bicicles" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Bicicles bicicles2 = new Bicicles(
         rs.getLong("IDBICICLETA"),rs.getString("PLACA"),rs.getString("MARCA"),rs.getString("MODELO"),rs.getString("CHASIS"),rs.getString("COLOR"),rs.getString("ID"),rs.getString("TIPOID"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"),rs.getDate("FECHA"),rs.getString("USERNAME"));
            
            
       list.add(bicicles2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
